package com.linux.huhx.thread3.join_1;

import java.util.concurrent.TimeUnit;

/**
 * @Author: huhx
 * @Date: 2017-10-30 上午 10:55
 */
public class MyThreadTest1{

    /**
     * 1. 在A线程中调用已经start的B线程的join方法，那么A线程会在join方法那里等待B线程执行完成再执行后续的代码。
     * 2.
     */
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new MyThread1();
        new MyThread1().start();
        thread.start();
        thread.join();
        System.out.println("I don't execute in main thread until MyThread1 executed");
    }
}

class MyThread1 extends Thread {
    @Override
    public void run() {
        try {
            int secondValue = (int) (Math.random() * 1000);
            System.out.println(secondValue);
            Thread.sleep(secondValue);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
